{extend name='public/base'}
{block name='layui-stgl'}layui-nav-itemed{/block}
{block name='stlb'}layui-this{/block}   
{block name='main'}
<div class="demoTable">
    搜索试题
    <div class="layui-inline">
        <input class="layui-input" name="value" id="examval" autocomplete="off">
    </div>
    <button class="layui-btn" data-type="reload" id="examsearch">搜索</button>
</div>
<table id="user1" lay-filter="user1" class="layui-bg-green"></table>
{/block}
{block name='js'}
<script text="text/javascript">
    layui.use('table', function () {
        var table = layui.table;
        var $ = layui.$;
        table.render({
            elem: '#user1',
            height:450,
            url: '{:url("admin/Exam/getExamData")}',
            cols: [
                [{
                    field: 'id',
                    width: 80,
                    title: 'ID',
                    sort: true
                }, {
                    field: 'examname',
                    title: '试题标题',
                },{
                    field: 'username',
                    title: '上传用户',

                },{
                     field: 'course',
                    title: '科目',
                },
                {
                     field: 'type',
                    title: '类型',
                },
                {
                     field: 'grade',
                    title: '年级',
                },
                {
                    field: 'file',
                    title: '查看',  
                    templet:function(d){
                        return '<a href="__UPLOADS__/'+d.username+'/'+d.file+' ">'+d.file+'</a>'
                    }
                }, {
                    field: 'status',
                    title: '状态',
                    edit: "text",
                    templet: function (d) {
                        if (d.status == 2) {
                            return '<span style="color:green">审核通过</span>';
                        } else if(d.status==1){  
                            return '<span style="color:blue">未审核</span>';
                        }else{
                            return '<span style="color:red">不通过</span>';
                        }
                    }
                }, {
                    field: 'create_time',
                    title: '申请时间',
                    sort: true
                }, ]
            ],
            page: {
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'],
                limit: 4, //每个表格显示几条记录
                limits: [5, 10, 15], //每页显示几条
                groups: 3, //显示一个连续页码
                first: true, //不显示首页   
                last: false, //不显示尾页 
            },
            id: 'idExam'
        });


        $('#examsearch').click(function() {
            table.reload('idExam', {
                where: { //设定异步数据接口的额外参数，任意设
                    value: $('#examval').val()
                },
                page: {
                    cur: 1 //重新从第 1 页开始
                }
            }); //只重载数据

        })
        table.on('edit(Exam)', function(obj) {
            var value = obj.value, //修改后的值
                data = obj.data, //得到所在行的键值 
                field = obj.field; //字段
            // layer.msg('[ID:' + data.id + '] ' + field + ' 字段更改为 ' + value);
            // layer.confirm("确认修改" + '[ID:' + data.id + '] ' + field + ' 字段更改为 ' + value, function() {
            layer.confirm("真的要修改么？", function() {
                $.ajax({
                    type: "get",
                    url: "{:url('admin/user/edit')}",
                    // data: "id=" + data.id + "&field=" + field + "&value" + value
                    data: data,
                    dataType: "json",
                    success: function(data) {
                        if (data.code == 200) {
                            layer.msg(data.msg, {
                                time: 500
                            }, function() {
                                window.location.reload();
                            })
                        } else {
                            layer.msg(data.msg, {
                                time: 1000
                            }, function() {
                                window.location.reload();

                            })
                        }
                    }
                })
            })
        });

    });

</script>
{/block}